<form  method="post" class="form-horizontal">
    <input type="hidden" name="id" value="{$notice.id}">
    <div class="form-group">
        <label class="col-md-3 col-xs-12 control-label"></label>
        <div class="col-md-6 col-xs-12">
            <h2>设置用户钻石</h2>
        </div>
    </div>

    <div class="form-group">
        <label class="col-md-3 col-xs-12 control-label">用户id</label>
        <div class="col-md-6 col-xs-12">
            <input name="user_id" type="number" id="user_id" onblur="check()" class="form-control"/>
        </div>
    </div>

    <div class="form-group">
        <label class="col-md-3 col-xs-12 control-label">用户昵称</label>
        <div class="col-md-6 col-xs-12">
            <input name="nickname" type="text" id="nickname" class="form-control" readonly />
        </div>
    </div>

    <div class="form-group">
        <label class="col-md-3 col-xs-12 control-label">用户微信号</label>
        <div class="col-md-6 col-xs-12">
            <input name="wechat_number" type="text" id="wechat_number" class="form-control" readonly/>
        </div>
    </div>

    <div class="form-group">
        <label class="col-md-3 col-xs-12 control-label">用户手机号</label>
        <div class="col-md-6 col-xs-12">
            <input name="phone" type="text" id="phone" class="form-control" readonly/>
        </div>
    </div>

    <div class="form-group">
        <label class="col-md-3 col-xs-12 control-label">用户当前钻石</label>
        <div class="col-md-6 col-xs-12">
            <input name="current_integral" type="text" id="current_integral" class="form-control" readonly/>
        </div>
    </div>

    <div class="form-group">
        <label class="col-md-3 col-xs-12 control-label">增减用户钻石(例如：增加：10 减少:-10)</label>
        <div class="col-md-6 col-xs-12">
            <input name="integral" type="number" id="integral" class="form-control"/>
        </div>
    </div>

    <div>
        <div class="col-md-3 col-xs-12"></div>
        <div class="col-md-6 col-xs-12">
            <present name="errorNote">
                <div class="alert alert-danger" role="alert">
                    <button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                    <strong>{$errorNote}</strong>
                </div>
            </present>
            <div class="form-group">
                <div class="col-md-6"><input type="reset" class="btn btn-block btn-default" value=" 清 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 空 " /></div>
                <div class="col-md-6"><button type="button" class="btn btn-block btn-info pull-right" onclick="save()"> 提 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 交 </button></div>
            </div>
        </div>
    </div>
    <!-- Modal -->
    <div class="modal fade" id="hint_modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                    <h4 class="modal-title" id="myModalLabel">提示</h4>
                </div>
                <div class="modal-body" id="hint_content">
                </div>
                <div class="modal-footer">
                    <button type="button" id="close_btn" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <!--<button type="button" class="btn btn-primary">Save changes</button>-->
                </div>
            </div>
        </div>
    </div>
</form>
<script type="text/javascript">
    function check(){
        var user_id = $("[name='user_id']").val();
        if(!user_id || user_id==''){
            $("#hint_content").empty().append("请输入会员ID！");
            $("#hint_modal").modal();
            return;
        }
        $.ajax({
            type: "POST",
            url: "__URL__/checkUserId",
            data: {
                user_id: user_id,
            },
            dataType: "json",
            success: function (data) {
                console.info(data);
                if(!data.success){
                    $("#nickname").val('');
                    $("#wechat_number").val('');
                    $("#phone").val('');
                    $("#current_integral").val('');
                    $("#hint_content").empty().append(data.message);
                    $("#hint_modal").modal();
                }else{
                    data = data.data;
                    $("#nickname").val(data.nickname);
                    $("#wechat_number").val(data.nickname);
                    $("#phone").val(data.phone);
                    $("#current_integral").val(data.integral);
                }
            }
        });
    }
    function save() {
        var user_id = $('#user_id').val();
        var integral = $('#integral').val();
//        var r = /^[0-9]+$/;
//        if(!r.test(integral)){
//            $("#hint_content").empty().append("请输入正确的钻石数目！");
//            $("#hint_modal").modal();
//            return;
//        }
        $.ajax({
            type: "POST",
            url: '__URL__/ajaxSetUserIntegral',
            data: {user_id:user_id,integral:integral},
            dataType: "json",
            success: function (data) {
                $("#hint_content").empty().append(data.message);
                $("#hint_modal").modal();
                if(data.success){
                    $('#close_btn').attr('onclick','jump()');
                }
            },
            error: function (data) {
                console.info(data);
                $("#hint_content").empty().append("请求超时！");
                $("#hint_modal").modal();
            }
        });
    }
    function jump() {
        window.location = '__URL__/';
    }
</script>